/*
 * TitleBar.fx
 * Created on 23-apr-2009, 12:30:36
 */

package fotoboek.assets;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextOrigin;


import javafx.fxd.Duplicator;

/**
 * @author r.mohammadi
 */

public class TitleBar {
public-init var UIAssets:Group on replace{
     def d =Duplicator{};
    content = d.duplicate(UIAssets.content[3]) as Group;
    skin = d.duplicate(content.content[0]) as Node;
    label = content.content[1] as Text;
    label.textAlignment = TextAlignment.CENTER;
    label.textOrigin = TextOrigin.BASELINE;
    label.translateY - 10;
    }
public-init var content:Group;
public-init var skin:Node;
public-init var label:Text;
public var text: String on replace {
        if (text != null) {
            label.content = text;
            align(skin, label);
        }
    }
 function align( target:Node, dest:Text ) {
        def destBounds = dest.boundsInLocal;
        def targetBounds = target.boundsInLocal;
        //println("{destBounds.minX}, {destBounds.minY}|{destBounds.width}x{destBounds.height}");
        // Delete unexpected Affine Transform created during translation by Production Suite
        delete dest.transforms;
        dest.translateY = 0;
        dest.translateX = 0;
        // center X
        dest.x =  (targetBounds.width - destBounds.width) / 2;
        //println("target {targetBounds.minX}, {targetBounds.minY}|{targetBounds.width}x{targetBounds.height}");
        dest.y = destBounds.height + (targetBounds.height - destBounds.height) / 2;

    }    
}